using System.Threading;
using System;

namespace DesignPattern.Creational.Singleton
{
    public class SingletonByDoubleIF
    {
        private static SingletonByDoubleIF _instance;
        private static Object _locker = new Object();
        private static int _createrThreadId;

        private SingletonByDoubleIF() {}

        public static SingletonByDoubleIF GetInstance()
        {
            if (_instance == null)
            {
                lock(_locker)
                {
                    if (_instance == null)
                    {
                        _instance = new SingletonByDoubleIF();
                        _createrThreadId = Thread.CurrentThread.ManagedThreadId;
                    }
                }
            }

            return _instance;
        }

        public void ShowCreater()
        {
            System.Console.WriteLine($"This Singleton instance is created by {_createrThreadId}");
        }
    }
}